package de.szut.entity;

import android.util.Log;

import java.io.Serializable;

/**
 * Created by dzebcuks on 23.08.13.
 */
public class User implements Serializable {

    private int totalUsers;

    private int infectedUsers;

    private int notInfectedUsers;

    private int controlledUsers;

    /**
     * Something like "dead". It just makes no sense to say dead for pc´s...
     */


    public User(int totalUsers) {
        this.totalUsers = totalUsers;
        this.infectedUsers = 0;
        this.controlledUsers = 0;
        this.notInfectedUsers = totalUsers;
    }

    public void clearAllUsers(){
        this.totalUsers = 0;
        this.infectedUsers = 0;
        this.notInfectedUsers =0;
        this.controlledUsers =0;
    }

    public int getControlledUsers() {
        return controlledUsers;
    }

    /**
     * Does not make that much sense to call this...
     * Setting the amount of controlled users on this way does NOT affect the amount of infected users.
     *
     * @param controlledUsers
     */
    public void setControlledUsers(int controlledUsers) {
        this.controlledUsers = controlledUsers;
    }

    public void addControlledDecreaseInfectedUsers(int controlledUsers) {
        this.controlledUsers += controlledUsers;
        this.infectedUsers -= controlledUsers;
    }

    public int getTotalUsers() {
        return this.totalUsers;
    }

    // should not be called
    public void setTotalUsers(int totalUsers) {
        this.totalUsers = totalUsers;
    }

    public void addTotalUsers(int usersToAdd) {
        this.totalUsers += usersToAdd;
        if(this.totalUsers < 0){
            Log.d("SPLASHER_LOGIC","NULL" + this.totalUsers +"____"+"added" + usersToAdd );
        }
    }

    public int getInfectedUsers() {
        return this.infectedUsers;
    }

    public int getNotInfectedUsers() {
        return this.notInfectedUsers;
    }

    public void setInfectedUsers(int infectedUsers) {
        this.infectedUsers = infectedUsers;
//        this.notInfectedUsers = this.totalUsers - this.infectedUsers;
    }

    public void setNotInfectedUsers(int notInfectedUsers) {
        this.notInfectedUsers = notInfectedUsers;
//        this.infectedUsers = this.totalUsers - this.notInfectedUsers;
    }

    public void addInfectedDecreaseNotInfectedUser(int infectedUsers){
        this.infectedUsers += infectedUsers;
        this.notInfectedUsers = this.notInfectedUsers - infectedUsers;
    }
    public void addInfectedUsers(int infectedUsers) {
        this.infectedUsers += infectedUsers;
//        this.notInfectedUsers = this.notInfectedUsers - infectedUsers;
    }

    public void addNotInfectedUsers(int notInfectedUsers) {
      this.notInfectedUsers +=  notInfectedUsers;
      if(this.notInfectedUsers < 0){
          Log.d("SPLASHER_LOGIC","NULL" + this.notInfectedUsers +"____"+"added" + notInfectedUsers );
      }
    }

    public double getPercentageOfInfection() {
        double value = (double)this.infectedUsers / (double)this.totalUsers *100.0;
        return value;
    }

    public double getPercentageOfNotInfected(){
        return (this.notInfectedUsers/ this.totalUsers)*100;
    }

    public double getPercentageOfControlling() {
        return (this.controlledUsers/ this.totalUsers) * 100.0 ;
    }

    public void setInfectedUsers(double percent) {
        this.infectedUsers = (int) Math.round(percent * this.totalUsers / 100);
        this.notInfectedUsers = this.totalUsers - this.infectedUsers;
    }
}
